// 病历信息右侧tabs --- 医嘱引用
import React from 'react';
import { Table, Tabs, Modal, Radio, Checkbox, Tree, Icon, Button, Select, Input, Drawer, Popconfirm, message, Tooltip, Card } from 'antd';
import { $http } from 'containers/config/https';
import { Util } from 'tools/index';
import store from 'store';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import DetailMedicalRecordTemplate from 'pages/common/DetailMedicalRecordTemplate.jsx';
import KnowledgeBasePreviewTemplate from 'pages/common/KnowledgeBasePreviewTemplate.jsx';
import CommonPagination from 'components/pagination/index';
import EMRVitalSigns from './EMRVitalSigns';
import '../style/CMOrderSave.less';

let loadPreviewTemplate = 0;
const { TabPane } = Tabs;
const { TreeNode } = Tree;
const { Option } = Select;
const { TextArea } = Input;

export default class CaseInformationPageTabs extends React.Component {
	constructor() {
		super();
		var recordData = JSON.parse(sessionStorage.getItem('patientData'));
		var userData = JSON.parse(sessionStorage.getItem('userData'));
		var locArr = userData && userData.locID ? [userData.locID] : [];
		this.state = {
			userData,
			tabsData: [], // tabs数据
			loading: false,
			doctorAdviceColumns: [], // 医嘱表头数据
			doctorAdviceTableData: [], // 医嘱表格数据
			doctorAdviceRadioData: [], // 长期、临时radio
			doctorAdviceRowKeys: [], // 医嘱选中key值
			doctorAdviceRows: [], // 医嘱选中数据
			tabsActiveKey: "knowledgeBase",
			doctorAdviceWidth: 0,
			doctorAdvicePage: 1,
			doctorAdvicePageSize: 10,
			doctorAdviceTotal: 0,
			recordData,
			radioValue: "1", // 就诊类型
			historyVisible: false, // 历史就诊弹窗
			historyADMTableData: [], // 医嘱历史就诊列表数据
			doctorAdviceHistoryColumns: [], // 医嘱历史就诊表头数据
			doctorAdviceHistoryWidth: 0,
			doctorAdviceHistoryRowKeys: [], // 医嘱历史选中key
			historyPage: 1,
			historyTotal: 0,
			historyPageSize: 10,
			radioButtonValue: '',
			inspectTableData: [], // 检查列表数据
			inspectColumns: [], // 检查表头数
			inspectWidth: 0,
			inspectPage: 1,
			inspectPageSize: 10,
			inspectTotal: 0,
			inspectRowKeys: [], // 检查选中key
			inspectRows: [],
			testTableData: [], // 检验列表数据
			testColumns: [], // 检验表头数据
			testWidth: 0,
			testPage: 1,
			testPageSize: 10,
			testTotal: 0,
			testRowKeys: [], // 检验选中key
			testRows: [],
			chineseHerbalMedicineColumns: [], // 中草药表头数据 
			chineseHerbalMedicineTableData: [], // 中草药列表数据 
			chineseHerbalMedicineWidth: 0,
			chineseHerbalMedicinePage: 1,
			chineseHerbalMedicinePageSize: 10,
			chineseHerbalMedicineTotal: 0,
			chineseHerbalMedicineRowKeys: [], // 中草药选中key
			chineseHerbalMedicineRowData: [],
			vitalSignsInitData: {}, // 生命体征初始化数据
			settDataActive: '', // 默认全部
			vitalSignsTableData: [], // 生命体征列表数据
			vitalSignsColumns: [], // 生命体征表头数据
			vitalSignsWidth: 0,
			vitalSignsPage: 1,
			vitalSignsPageSize: 10,
			vitalSignsTotal: 0,
			vitalSignsRowKeys: [], //生命体征选中key
			inspectRadioValue: "", // 检查radio
			inspectionRadioValue: "", // 检验radio
			vitalSignsRadioValue: "", // 生命体征radio
			pathologicalTableData: [], // 病理列表数据
			pathologicalColumns: [], // 病理表头数据
			pathologicalWidth: 0,
			pathologicalPage: 1,
			pathologicalPageSize: 10,
			pathologicalTotal: 0,
			pathologicalRowKeys: [], // 病理选中key
			inspectDetailTableData: [], // 检查明细列表数据
			inspectDetailWidth: 0, //  
			testDetailColumns: [], // 检验明细表头数据
			testDetailTableData: [], // 检验明细列表数据
			testDetailWidth: 0,
			inspectionFindingsCheck: false, // 检查所见
			diagnosticOpinionCheck: false, // 诊断意见
			inspectionMethod: false, // 检查方法
			knowledgeBaseTreeData: [], // 知识库树数据
			knowledgeBaseSelectedKeys: [],
			knowledgeBaseTreeSelectData: {}, // 知识库选中数据
			// doctorAdviceQuoteValue: "ordDate+ordTime+medDesc+ordFreqDesc+ordDoseUnitDesc", // 医嘱引用方式
			currentRadio: 'ALLHosp', // 就诊科室
			locRadioValue: 'O', // 就诊类型
			currentDoc: false, // 当前医师
			historyAdmPageSize: 10,
			historyAdmPage: 1,
			historyAdmTotal: 0, // 历史就诊总条数
			historyAdmData: [], // 历史就诊数据
			drawerVisible: false, // 抽屉是否显示
			treeSelectData: {},
			modalRowData: {},
			admRowData: {}, // 历史就诊当前操作行
			previewVisible: false,
			previewTemplatePath: "",
			previewDataSource: [],
			menuVisible: false,
			contextMenuData: {}, // 右击树对应的行数据
			knowledgeBaseVisible: false, // 知识库维护
			knowledgeBaseNodeTitle: undefined, // 知识库节点描述
			knowledgeBaseFiledID: "", // 病历中知识库输入域filedID
			nodeContent: undefined, // 知识库内容
			autoExpandParent: true, // 是否自动展开父节点
			expandedKeys: [],
			KnowledgeBaseTypeValue: "1",
			knowledgeBaseTypeData: [{
				id: "1",
				descripts: "个人",
				descriptsSPCode: "gr"
			}, {
				id: "2",
				descripts: "科室",
				descriptsSPCode: "ks"
			}],
			locSelectData: [], // 科室下拉数据
			locArr,
			showAddKnowledgeCatalog: false,//新增目录弹框显示  
			knowledgeCatalogDesc: '',
			historyAdmID: '',
			insertMethod: 'transverse', //  横排： transverse  竖排： vertical
		};
	}

	static getDerivedStateFromProps(nextProps, prevState) {
		//该方法内禁止访问this
		if (nextProps.historyAdmID !== prevState.historyAdmID) {
			//通过对比nextProps和prevState，返回一个用于更新状态的对象
			return true
		}
		//不需要更新状态，返回null
		return null
	}

	componentDidMount() {
		this.getTabsData();
		this.props.onRef(this);
		// 添加右键点击、点击事件监听
		this.getLocSelectData(); // 获取科室下拉数据
		// document.getElementById("table").addEventListener('contextmenu', this.handleContextMenu)
		document.addEventListener('click', this.handleClick)
	}

	// static getDerivedStateFromProps(nextProps, prevState) {
	// 	const {treeSelectData, modalRowData} = nextProps;
	// 	if (JSON.stringify(treeSelectData) !== JSON.stringify(prevState.treeSelectData)) {
	// 		return {
	// 			treeSelectData
	// 		}
	// 	}
	// 	if (JSON.stringify(modalRowData) !== JSON.stringify(prevState.modalRowData)) {
	// 		return {
	// 			modalRowData
	// 		}
	// 	}
	// 	return null;
	// }

	componentDidUpdate(prevProps, prevState) {
		if (this.state.tabsActiveKey === "EMRCitingHistoryAdm") { // 当切换到历史就诊时
			const { treeSelectData, modalRowData } = prevProps;
			if ((JSON.stringify(treeSelectData) !== JSON.stringify(prevState.treeSelectData)) || (JSON.stringify(modalRowData) !== JSON.stringify(prevState.modalRowData))) {
				this.setState({ treeSelectData, modalRowData }, () => {
					this.getHistoryAdmData();
				})
			}
		}
		if (this.props.historyAdmID && (this.props.historyAdmID !== this.state.historyAdmID)) {
			this.setState({ historyAdmID: this.props.historyAdmID }, () => {
				this.handleTabsChange(this.state.tabsActiveKey)
			})
		}
	}

	componentWillUnmount() {
		// 移除事件监听
		// document.getElementById("table").removeEventListener('contextmenu', this.handleContextMenu)
		document.removeEventListener('click', this.handleClick)
		this.setState = (state, callback) => { return; }
	}

	onDoctorAdviceColumnRef = (ref) => {
		this.doctorAdviceColumnRef = ref;
	}

	// 获取tabs数据
	getTabsData = () => {
		let data = {
			params: [{
				compontName: "EMRCitingResources",
				type: "C",
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let arr = res.result && res.result.C && res.result.C.length > 0 ? res.result.C : [];
					this.setState({ tabsData: arr, tabsActiveKey: arr[0].code }, () => {
						this.handleTabsChange(this.state.tabsActiveKey)
					})
				}
			}
		})
	}

	// tabs切换
	handleTabsChange = activeKey => {
		// console.log(activeKey)
		// 重置就诊类型以及历史就诊选中记录
		this.setState({ tabsActiveKey: activeKey, radioValue: "1", doctorAdviceHistoryRowKeys: [], historyPageSize: 10, historyPage: 1 }, () => {
			// 当tabs为知识库、专科知识库以及为历史就诊是不取表头数据
			(this.state.tabsActiveKey === "knowledgeBase") || (this.state.tabsActiveKey === "SpecializedKnowledgeBase") || (this.state.tabsActiveKey === "EMRCitingHistoryAdm") ? "" : this.getDoctorAdviceColumns(); // 获取医嘱表头数据
			if (this.state.tabsActiveKey === "QuoteResourcesOrder") { // 医嘱
				// if (!(this.state.doctorAdviceTableData&&this.state.doctorAdviceTableData.length > 0)) {
				this.getDoctorAdviceTableData(); // 获取医嘱列表数据
				this.getRuleOfReference("QuoteResourcesOrder"); // 获取医嘱界面引用规则
				// }
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesExamine") { // 检查
				this.getInspectTableData(); // 获取检查列表数据
				this.getRuleOfReference("EMRCitingResourcesExamine"); // 获取检查界面引用规则
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesInspection") { // 检验
				if (!(this.state.testDetailColumns && this.state.testDetailColumns.length > 0)) {
					this.getDetailColumns("EMRCitingResourcesInspectSub");
				}
				this.getTestTableData(); // 获取检验列表数据
				this.getRuleOfReference("EMRCitingResourcesInspection"); // 获取检查界面引用规则
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesCMMed") { // 中草药
				// if (!(this.state.chineseHerbalMedicineTableData&&this.state.chineseHerbalMedicineTableData.length > 0)) {
				this.getChineseHerbalMedicineTableData(); // 获取中草药列表数据
				this.getRuleOfReference("EMRCitingResourcesCMMed"); // 获取中草药界面引用规则
				// }
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesTemperature") { // 生命体征
				// if (!(this.state.vitalSignsTableData&&this.state.vitalSignsTableData.length > 0)) {
				// this.getVitalSignsTableData(); // 获取生命体征列表数据
				// this.getRuleOfReference("EMRCitingResourcesTemperature"); // 获取生命体征界面引用规则
				// }
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesPathological") { // 病理
				this.getPathologicalTableData(); // 获取病理列表数据
				this.getRuleOfReference("EMRCitingResourcesPathological"); // 获取病理界面引用规则
			} else if (this.state.tabsActiveKey === "EMRCitingHistoryAdm") { // 历史就诊
				// if (!(this.state.historyAdmData&&this.state.historyAdmData.length > 0)) {
				// 	this.getHistoryAdmData();
				// }
			} else if (this.state.tabsActiveKey === "knowledgeBase") {
				console.log("知识库");
			}
		})
	}

	// 获取医嘱表头
	getDoctorAdviceColumns = (name) => {
		let { tabsActiveKey } = this.state;
		let data = {
			params: [{
				compontName: name ? name : tabsActiveKey,
				type: "",
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					var totalWidth = 0;
					let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
						return {
							...item,
							key: index,
							widthNum: parseInt(item.width),
							title: <div onDoubleClick={!name ? this.doctorAdviceColumnRef.onOpenModel : this.doctorAdviceHistoryColumnRef.onOpenModel}>{item.title}</div>,
						}
					}) : '';
					let filterArr = arr.filter(function (item) { return item.display === 'Y' });
					for (var i = 0; i < filterArr.length; i++) {
						totalWidth += filterArr[i].widthNum;
					}
					if (name) { // 历史就诊
						if (name === "EMRCitingResourcesHistoryAdm") { // 医嘱历史就诊
							this.setState({ doctorAdviceHistoryColumns: filterArr, doctorAdviceHistoryWidth: totalWidth })
						}
					} else {
						if (tabsActiveKey === "QuoteResourcesOrder") { // 医嘱
							this.setState({ doctorAdviceColumns: filterArr, doctorAdviceWidth: totalWidth, doctorAdviceRadioData: res.result.B })
						} else if (tabsActiveKey === "EMRCitingResourcesExamine") { // 检查
							this.setState({ inspectColumns: filterArr, inspectWidth: totalWidth })
						} else if (tabsActiveKey === "EMRCitingResourcesInspection") { // 检验
							this.setState({ testColumns: filterArr, testWidth: totalWidth })
						} else if (tabsActiveKey === "EMRCitingResourcesCMMed") { // 中草药
							this.setState({ chineseHerbalMedicineColumns: filterArr, chineseHerbalMedicineWidth: totalWidth })
						} else if (tabsActiveKey === "EMRCitingResourcesTemperature") { // 生命体征
							this.setState({ vitalSignsColumns: filterArr, vitalSignsWidth: totalWidth })
						} else if (tabsActiveKey === "EMRCitingResourcesPathological") { // 病理
							this.setState({ pathologicalColumns: filterArr, pathologicalWidth: totalWidth })
						}
					}
				}
			}
		})
	}

	// 获取医嘱列表数据
	getDoctorAdviceTableData = (arr) => {
		this.setState({ loading: true })
		let { historyAdmID, recordData, radioButtonValue, doctorAdvicePage, doctorAdvicePageSize } = this.state;
		if (!((recordData && recordData.admID) || historyAdmID)) {
			this.setState({ loading: false })
			return;
		}
		let admIDArr = [];
		admIDArr.push(historyAdmID || recordData.admID);
		let data = {
			params: [{
				admID: arr && arr.length > 0 ? arr : admIDArr,
				ordPriorityCode: radioButtonValue
			}],
			pagination: [{
				pageSize: doctorAdvicePageSize,
				currentPage: doctorAdvicePage
			}]
		}
		$http.post('urlS', this, {
			code: "06010070",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let doctorAdviceTableData = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : []
					for (var i = 0; i < doctorAdviceTableData.length; i++) {
						doctorAdviceTableData[i].key = i
					}
					this.setState({
						loading: false, doctorAdviceTableData, doctorAdviceRowKeys: [], doctorAdviceRows: [],
						doctorAdviceTotal: res.result && res.result.totalCount ? res.result.totalCount : 0
					}, () => {
						arr && arr.length > 0 ? this.handleHistoryCancel() : ""; // 关闭弹窗
					});
				} else {
					this.setState({ loading: false, doctorAdviceTableData: [], doctorAdviceTotal: 0 })
				}
			}
		})
	}

	// 获取历史就诊记录
	getHistoryADMTableData = () => {
		this.setState({ loading: true })
		let { recordData, historyPage, historyPageSize, historyAdmID } = this.state;
		let data = {
			params: [{
				admID: historyAdmID || recordData.admID,
			}],
			pagination: [{
				pageSize: historyPageSize,
				currentPage: historyPage
			}]
		}
		$http.post('urlS', this, {
			code: "06010069",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let historyADMTableData = res.result && res.result.Data && res.result.Data.length > 0 ? res.result.Data : []
					for (var i = 0; i < historyADMTableData.length; i++) {
						historyADMTableData[i].key = i
					}
					this.setState({ historyADMTableData, loading: false, historyTotal: res.result.totalCount })
				} else {
					this.setState({ loading: false, historyADMTableData: [], historyTotal: 0 })
				}
			}
		})
	}

	// 就诊类型
	radioChange = e => {
		if (e.target.value === "1") {
			// 隐藏历史就诊弹窗
			this.setState({ radioValue: e.target.value }, () => {
				if (this.state.tabsActiveKey === "QuoteResourcesOrder") { // 医嘱
					this.getDoctorAdviceTableData();
				} else if (this.state.tabsActiveKey === "EMRCitingResourcesExamine") { // 检查
					this.getInspectTableData(); // 获取检查列表数据
				} else if (this.state.tabsActiveKey === "EMRCitingResourcesInspection") { // 检验
					this.getTestTableData(); // 获取检验列表数据
				} else if (this.state.tabsActiveKey === "EMRCitingResourcesCMMed") { // 中草药
					this.getChineseHerbalMedicineTableData(); // 获取中草药列表数据
				} else if (this.state.tabsActiveKey === "EMRCitingResourcesTemperature") { // 生命体征
					this.getVitalSignsTableData(); // 获取生命体征列表数据
				} else if (this.state.tabsActiveKey === "EMRCitingResourcesPathological") { // 病理
					this.getPathologicalTableData(); // 获取病理列表数据
				}
			});
		} else if (e.target.value === "2") {
			// 显示历史就诊弹窗
			this.handleShowModal();
		}
	}

	handleRadioClick = () => {
		if (this.state.radioValue === "2") {
			// 显示历史就诊弹窗
			this.handleShowModal();
		}
	}

	// 打开历史就诊弹窗
	handleShowModal = () => {
		this.setState({ historyVisible: true }, () => {
			if (!(this.state.doctorAdviceHistoryColumns && this.state.doctorAdviceHistoryColumns.length > 0)) {
				this.getDoctorAdviceColumns("EMRCitingResourcesHistoryAdm");
				this.getHistoryADMTableData();
			}
		})
	}

	// 关闭历史就诊弹窗
	handleHistoryCancel = () => {
		this.setState({ historyVisible: false });
	}

	// 历史就诊确认操作
	handleHistoryOk = () => {
		this.setState({ radioValue: "2" }, () => {
			if (this.state.tabsActiveKey === "QuoteResourcesOrder") { // 医嘱
				this.getDoctorAdviceTableData(this.state.doctorAdviceHistoryRowKeys);
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesExamine") { // 检查
				this.getInspectTableData(this.state.doctorAdviceHistoryRowKeys); // 获取检查列表数据
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesInspection") { // 检验
				this.getTestTableData(this.state.doctorAdviceHistoryRowKeys); // 获取检验列表数据
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesCMMed") { // 中草药
				this.getChineseHerbalMedicineTableData(this.state.doctorAdviceHistoryRowKeys); // 获取中草药列表数据
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesTemperature") { // 生命体征
				this.getVitalSignsTableData(this.state.doctorAdviceHistoryRowKeys); // 获取生命体征列表数据
			} else if (this.state.tabsActiveKey === "EMRCitingResourcesPathological") { // 病理
				this.getPathologicalTableData(this.state.doctorAdviceHistoryRowKeys); // 获取生命体征列表数据
			}
		})
	}

	onDoctorAdviceHistoryColumnRef = ref => {
		this.doctorAdviceHistoryColumnRef = ref;
	}

	// 获取检查列表数据
	getInspectTableData = (arr) => {
		this.setState({ loading: true });
		let { historyAdmID, recordData, inspectRadioValue, inspectPage, inspectPageSize } = this.state;
		let admIDArr = [];
		admIDArr.push(historyAdmID || recordData.admID);
		let data = {
			params: [{
				admID: arr && arr.length > 0 ? arr : admIDArr,
				power: "EMRCitingResourcesExamine",
				queryTime: inspectRadioValue,
			}],
			pagination: [{
				pageSize: inspectPageSize,
				currentPage: inspectPage
			}]
		}
		$http.post('urlS', this, {
			code: "06010073",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let inspectTableData = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : []
					for (var i = 0; i < inspectTableData.length; i++) {
						inspectTableData[i].key = i
					}
					this.setState({
						inspectTableData, loading: false,
						inspectTotal: res.result && res.result.totalCount ? res.result.totalCount : 0,
						inspectRowKeys: [], inspectRows: []
					}, () => {
						arr && arr.length > 0 ? this.handleHistoryCancel() : ""; // 关闭弹窗
					})
				} else {
					this.setState({ loading: false, inspectTableData: [], inspectTotal: 0 })
				}
			}
		})
	}

	// 临时、长期、出院带药radio
	radioButtonChange = e => {
		console.log("临时、长期、出院带药radio", e)
		this.setState({ radioButtonValue: e.target.value }, () => {
			// 查询医嘱列表
			this.getDoctorAdviceTableData();
		})
	}

	// 获取检验列表数据
	getTestTableData = (arr) => {
		this.setState({ loading: true });
		let { historyAdmID, recordData, inspectionRadioValue, testPage, testPageSize } = this.state;
		let admIDArr = [];
		admIDArr.push(historyAdmID || recordData.admID);
		let data = {
			params: [{
				admID: arr && arr.length > 0 ? arr : admIDArr,
				power: "EMRCitingResourcesInspection",
				queryTime: inspectionRadioValue,
			}],
			pagination: [{
				pageSize: testPageSize,
				currentPage: testPage
			}]
		}
		$http.post('urlS', this, {
			code: "06010072",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let testTableData = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : []
					for (var i = 0; i < testTableData.length; i++) {
						testTableData[i].key = i
					}
					this.setState({
						testTableData, loading: false,
						testTotal: res.result && res.result.totalCount ? res.result.totalCount : 0,
						testRowKeys: [], testRows: []
					}, () => {
						arr && arr.length > 0 ? this.handleHistoryCancel() : ""; // 关闭弹窗
					})
				} else {
					this.setState({ loading: false, testTableData: [], testTotal: 0 })
				}
			}
		})
	}

	// 获取中草药列表数据
	getChineseHerbalMedicineTableData = (arr) => {
		this.setState({ loading: true });
		let { historyAdmID, recordData, chineseHerbalMedicinePage, chineseHerbalMedicinePageSize } = this.state;
		let admIDArr = [];
		admIDArr.push(historyAdmID || recordData.admID);
		let data = {
			params: [{
				admID: arr && arr.length > 0 ? arr : admIDArr,
				power: "EMRCitingResourcesCMMed"
			}],
			pagination: [{
				pageSize: chineseHerbalMedicinePageSize,
				currentPage: chineseHerbalMedicinePage
			}]
		}
		$http.post('urlS', this, {
			code: "06010071",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let chineseHerbalMedicineTableData = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : []
					for (var i = 0; i < chineseHerbalMedicineTableData.length; i++) {
						chineseHerbalMedicineTableData[i].key = i
					}
					this.setState({
						chineseHerbalMedicineTableData, loading: false,
						chineseHerbalMedicineTotal: res.result && res.result.totalCount ? res.result.totalCount : 0,
						chineseHerbalMedicineRowKeys: [], chineseHerbalMedicineRowData: []
					}, () => {
						arr && arr.length > 0 ? this.handleHistoryCancel() : ""; // 关闭弹窗
					})
				} else {
					this.setState({ loading: false, chineseHerbalMedicineTableData: [], chineseHerbalMedicineTotal: 0 })
				}
			}
		})
	}

	// 获取生命体征列表数据
	getVitalSignsTableData = () => {
		// old生命体征
		let { historyAdmID, recordData, vitalSignsRadioValue, vitalSignsPage, vitalSignsPageSize } = this.state;
		let admIDArr = [];
		admIDArr.push(historyAdmID || recordData.admID);
		let data = {
			params: [{
				admID: arr && arr.length > 0 ? arr : admIDArr,
				power: "EMRCitingResourcesTemperature",
				queryTime: vitalSignsRadioValue,
			}],
			pagination: [{
				pageSize: vitalSignsPageSize,
				currentPage: vitalSignsPage
			}]
		}
		$http.post('urlS', this, {
			code: "06010074",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let vitalSignsTableData = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : []
					for (var i = 0; i < vitalSignsTableData.length; i++) {
						vitalSignsTableData[i].key = i
					}
					this.setState({ vitalSignsTableData: res.result, loading: false, vitalSignsTotal: res.result && res.result.totalCount ? res.result.totalCount : 0 }, () => {
						arr && arr.length > 0 ? this.handleHistoryCancel() : ""; // 关闭弹窗
					})
				} else {
					this.setState({ loading: false, vitalSignsTableData: [], vitalSignsTotal: 0 })
				}
			}
		})
	}

	// 检查radio
	inspectRadioChange = e => {
		this.setState({ inspectRadioValue: e.target.value });
	}

	// 检查radio
	inspectionRadioChange = e => {
		this.setState({ inspectionRadioValue: e.target.value });
	}

	// 生命体征
	vitalSignsRadioChange = e => {
		this.setState({ vitalSignsRadioValue: e.target.value });
	}

	// 获取病理列表数据
	getPathologicalTableData = (arr) => {
		this.setState({ loading: true });
		let { historyAdmID, recordData, vitalSignsRadioValue, pathologicalPage, pathologicalPageSize } = this.state;
		let admIDArr = [];
		admIDArr.push(historyAdmID || recordData.admID);
		let data = {
			params: [{
				admID: arr && arr.length > 0 ? arr : admIDArr,
				power: "EMRCitingResourcesTemperature",
				queryTime: vitalSignsRadioValue,
			}],
			pagination: [{
				pageSize: pathologicalPageSize,
				currentPage: pathologicalPage
			}]
		}
		$http.post('urlS', this, {
			code: "06010075",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let pathologicalTableData = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : []
					for (var i = 0; i < pathologicalTableData.length; i++) {
						pathologicalTableData[i].key = i
					}
					this.setState({ pathologicalTableData: res.result, loading: false, pathologicalTotal: res.result && res.result.totalCount ? res.result.totalCount : 0 }, () => {
						arr && arr.length > 0 ? this.handleHistoryCancel() : ""; // 关闭弹窗
					})
				} else {
					this.setState({ loading: false, pathologicalTableData: [], pathologicalTotal: 0 })
				}
			}
		})
		// 
		this.setState({ pathologicalTableData: [] })
	}

	// 历史就诊改变条数
	handleHistoryPageSizeChange = (current, size) => {
		this.setState({ historyPage: 1, historyPageSize: size }, () => {
			// 重新查询历史就诊数据
			this.getHistoryADMTableData();
		})
	}

	// 历史就诊页数切换
	handleHistoryPageChange = (page, pageSize) => {
		this.setState({ historyPage: page, historyPageSize: pageSize }, () => {
			// 重新查询历史就诊数据
			this.getHistoryADMTableData();
		})
	}

	// 医嘱条数切换
	handleDoctorAdvicePageSizeChange = (current, size) => {
		this.setState({ doctorAdvicePage: 1, doctorAdvicePageSize: size }, () => {
			// 重新查询医嘱数据
			this.getDoctorAdviceTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 医嘱页数切换
	handleDoctorAdvicePageChange = (page, pageSize) => {
		this.setState({ doctorAdvicePage: page, doctorAdvicePageSize: pageSize }, () => {
			// 重新查询医嘱数据
			this.getDoctorAdviceTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 检查条数切换
	handleInspectPageSizeChange = (current, size) => {
		this.setState({ inspectPage: 1, inspectPageSize: size }, () => {
			// 重新查询检查数据
			this.getInspectTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 检查页数切换
	handleInspectPageChange = (page, pageSize) => {
		this.setState({ inspectPage: page, inspectPageSize: pageSize }, () => {
			// 重新查询医嘱数据
			this.getInspectTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 检验条数切换
	handleTestPageSizeChange = (current, size) => {
		this.setState({ testPage: 1, testPageSize: size }, () => {
			// 重新查询检查数据
			this.getTestTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 检验页数切换
	handleTestPageChange = (page, pageSize) => {
		this.setState({ testPage: page, testPageSize: pageSize }, () => {
			// 重新查询医嘱数据
			this.getTestTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 病理条数切换
	handlePathologicalPageSizeChange = (current, size) => {
		this.setState({ pathologicalPage: 1, pathologicalPageSize: size }, () => {
			// 重新查询检查数据
			this.getPathologicalTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 病理页数切换
	handlePathologicalPageChange = (page, pageSize) => {
		this.setState({ pathologicalPage: page, pathologicalPageSize: pageSize }, () => {
			// 重新查询医嘱数据
			this.getPathologicalTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 中草药条数切换
	handleChineseHerbalMedicinePageSizeChange = (current, size) => {
		this.setState({ chineseHerbalMedicinePage: 1, chineseHerbalMedicinePageSize: size }, () => {
			// 重新查询检查数据
			this.getChineseHerbalMedicineTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 中草药页数切换
	handleChineseHerbalMedicinePageChange = (page, pageSize) => {
		this.setState({ chineseHerbalMedicinePage: page, chineseHerbalMedicinePageSize: pageSize }, () => {
			// 重新查询医嘱数据
			this.getChineseHerbalMedicineTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 生命体征条数切换
	handleVitalSignsPageSizeChange = (current, size) => {
		this.setState({ vitalSignsPage: 1, vitalSignsPageSize: size }, () => {
			// 重新查询检查数据
			this.getVitalSignsTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 生命体征页数切换
	handleVitalSignsPageChange = (page, pageSize) => {
		this.setState({ vitalSignsPage: page, vitalSignsPageSize: pageSize }, () => {
			// 重新查询医嘱数据
			this.getVitalSignsTableData(this.state.radioValue === "2" ? this.state.doctorAdviceHistoryRowKeys : []);
		})
	}

	// 检查所见
	inspectionFindingsChange = e => {
		// console.log(e.target.checked)
		this.setState({ inspectionFindingsCheck: e.target.checked })
	}

	// 诊断意见
	diagnosticOpinionCheckChange = e => {
		this.setState({ diagnosticOpinionCheck: e.target.checked })
	}

	// 检查方法
	inspectionMethodChange = e => {
		this.setState({ inspectionMethod: e.target.checked })
	}

	// 获取检查明细列表数据
	getInspectDetailTableData = () => {
		this.setState({ inspectDetailTableData: [] });
	}

	// 获取明细表头数据
	getDetailColumns = (name) => {
		let data = {
			params: [{
				compontName: name,
				type: "",
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
						return {
							...item,
							widthNum: parseInt(item.width),
							key: index,
							title: <div onDoubleClick={this.detailColumnRef.onOpenModel}>{item.title}</div>,
						}
					}) : '';
					let filterArr = arr.filter(function (item) { return item.display === 'Y' });
					if (name === "EMRCitingResourcesInspectSub") { // 检验明细
						this.setState({ testDetailColumns: filterArr, testDetailWidth: res.totalWidth })
					}
				}
			}
		})
	}

	// 获取检验明细列表数据
	getTestDetailTableData = () => {
		this.setState({ testDetailTableData: [] });
	}

	onDetailColumnRef = ref => {
		this.detailColumnRef = ref;
	}

	// 处理tree数据
	filterTreeData = treeData => {
		let data = treeData && treeData.map(item => {
			return {
				title: item.descripts,
				key: item.treeType + item.ID,
				...item,
				children: this.filterTreeData(item.subCatalogue)
			}
		});
		return data;
	}

	// 获取知识库目录树
	getKnowledgeBaseTreeData = (id, modalRowData, isCancel) => {
		// console.log(modalRowData)
		let data = {
			params: [{
				FieldID: id,
				versionID: modalRowData && modalRowData.releaseVersion ? modalRowData.releaseVersion : undefined,
				flag: "1",
			}]
		}
		$http.post('urlS', this, {
			code: "06070001",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let result = [];
					if (res.result && res.result.ID) {
						result.push(res.result);
					} else {
						result = res.result;
					}

					let arr = result && result.length > 0 ? this.filterTreeData(result) : [];
					let expandedKeys = []; // 默认展开的节点
					let parentKey = res.result && res.result.ID ? res.result.treeType + res.result.ID : "";
					expandedKeys.push(parentKey)
					/**
					* @ByShizi: 电子病历输入域聚焦时跳转自动跳转到知识库，然后公共知识库手动展开后切换一个输入域又会自动收起
					* 需求 #822
					* Create 2022-07-28
					*/
					this.setState({
						// expandedKeys: isCancel ? this.state.expandedKeys : expandedKeys,
						knowledgeBaseTreeData: arr,
						knowledgeBaseFiledID: id,
						modalRowData
					}, () => {
						// if (this.state.knowledgeBaseTreeData && this.state.knowledgeBaseTreeData.length > 0) {
						// 	this.setState({ tabsActiveKey: "knowledgeBase", knowledgeBaseFiledID: id, modalRowData })
						// }
						if (!isCancel) {
							this.handlePreviewCancel();
						}
					})
				}
			}
		})
	}

	// 清除知识库目录树
	clearKnowledgeBaseTreeData = () => {
		this.setState({
			expandedKeys: [],
			knowledgeBaseTreeData: [],
			knowledgeBaseFiledID: "",
		})
	}

	renderTreeNodes = (data) => data.map(item => {
		let type = (item.treeType === 'MAINCATALOG' || item.treeType === 'CATALOG') ? 'folder-open' : (item.treeType === 'CATALOG' ? 'folder' : 'file');
		if (item.children) {
			return (
				<TreeNode icon={<Icon type={type} />} title={
					<Tooltip title={item && item.nodeContent && !this.handleDetermineWhetherItIsXML(item.nodeContent) ? item.nodeContent : ""}>
						<span style={{ cursor: "pointer" }}>{item.title}</span>
					</Tooltip>
				} key={item.key} dataRef={item}>
					{this.renderTreeNodes(item.children)}
				</TreeNode>
			);
		}
		return <TreeNode icon={<Icon type={type} />} title={
			<Tooltip title={item && item.nodeContent && !this.handleDetermineWhetherItIsXML(item.nodeContent) ? item.nodeContent : ""}>
				<span style={{ cursor: "pointer" }}>{item.title}</span>
			</Tooltip>
			// <span style={{ cursor: "pointer" }} title={item && item.nodeContent ? item.nodeContent : item.title}>{item.title}</span>
		} key={item.key} dataRef={item} />;
	});

	// 知识库节点点击预览
	handleTreeNodesClick = () => {
		let item = this.state.contextMenuData;
		if (item.treeType === "TEMPLATE" && item.nodeContent && this.handleDetermineWhetherItIsXML(item.nodeContent)) {
			this.setState({ knowledgeBaseTreeSelectData: item, previewVisible: true }, () => {
				this.getChapterXml(this.state.knowledgeBaseTreeSelectData, 'preview')
			})
		}
	}

	// 知识库树选中操作
	knowledgeBaseOnSelect = (keys, event) => {
		console.log("知识库树选中操作", event)
		let rowData = event.node.props.dataRef;
		this.setState({ knowledgeBaseSelectedKeys: keys }, () => {
			if (this.state.knowledgeBaseSelectedKeys && this.state.knowledgeBaseSelectedKeys.length > 0) {
				this.setState({ knowledgeBaseTreeSelectData: rowData }, () => {
					// if (!(this.state.knowledgeBaseTreeSelectData && this.state.knowledgeBaseTreeSelectData.treeType === "TEMPLATE" && !this.state.knowledgeBaseTreeSelectData.nodeContent)) { // 选中时如果非知识库模板则关闭预览
					// 	this.setState({ previewVisible: false })
					// }
					// this.getChapterXml(this.state.knowledgeBaseTreeSelectData, 'preview')
				})
			} else {
				this.setState({ knowledgeBaseTreeSelectData: {} })
			}
		})
	}

	// 双击目录树
	knowledgeBaseDoubleClick = (event, record) => {
		let key = [], rowData = record.props.dataRef;
		key.push(rowData.treeType + rowData.ID);
		if (rowData.treeType === "TEMPLATE") {
			this.setState({ knowledgeBaseTreeSelectData: rowData, knowledgeBaseSelectedKeys: key }, () => {
				this.getChapterXml(this.state.knowledgeBaseTreeSelectData)
			})
		}
	}

	// 获取章节xml
	getChapterXml = (rowData, source) => {
		let { knowledgeBaseFiledID } = this.state;
		let nodeContent = rowData && rowData.nodeContent ? rowData.nodeContent : "";
		// if (!nodeContent) {
		// 	message.error("该知识库内容为空，请维护之后再插入。");
		// }
		if (nodeContent && nodeContent.indexOf("<XTextDocument") === -1) { // 如果nodeContent存在并且不包含<XTextDocument时走字符串插入
			this.props.knowledgeBaseAssignment && this.props.knowledgeBaseAssignment(knowledgeBaseFiledID, nodeContent)
		} else {
			let data = {
				params: [{
					knowledgeNodeID: rowData.ID
				}]
			}
			$http.post('urlDeault', this, {
				code: "06010082",
				data: data,
				success: (res) => {
					if (+res.errorCode === 0) {
						this.setState({
							knowledgeNodeContent: res.result && res.result.knowledgeNodeContent ? res.result.knowledgeNodeContent : "",
							// previewVisible: true, 
							previewTemplatePath: res.result && res.result.templatePath ? res.result.templatePath : "",
							previewDataSource: res.result && res.result.dataSource ? res.result.dataSource : []
						}, () => {
							if (source === "preview") {
								this.loadPreviewTemplate();
							} else {
								// 直接引用
								this.handlePreviewOk();
							}

							// this.loadPreviewTemplate()
							// this.state.previewTemplatePath ? this.previewTemplateChild.setElementTextByID(this.state.previewTemplatePath, res.result.dataSource) : this.previewTemplateChild.NewFile();
						})
						// if (router) { // 单击预览
						// 	// 打开病例预览弹窗

						// } else { // 双击插入知识库
						// 	this.props.setKnowledgeBaseXMl(this.state.knowledgeNodeContent, rowData);
						// }
					}
				}
			})
		}
	}

	// 获取引用规则
	getRuleOfReference = (ruleCode) => {
		let data = {
			params: [{
				power: "DocEMRResource",
				eMRResourceRuleCode: ruleCode
			}]
		}
		$http.post('urlDeault', this, {
			code: "06010079",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					this.setState({ ruleOfReferences: res.result });
				}
			}
		})
	}

	// 引用规则
	handleRuleReference = (arr, values) => {
		const { insertMethod } = this.state;
		let valueArr = values.split("+");
		let str = ""
		for (let i = 0; i < arr.length; i++) {
			str += i + 1 + "、";
			for (let j = 0; j < valueArr.length; j++) {
				if (arr[i][valueArr[j]]) {
					str += arr[i][valueArr[j]] + ' ';
				}
			}
			str += (i === arr.length - 1) ? '' : (insertMethod === 'vertical' ? '\n' : '，');
		}
		return str;
	}

	// 医嘱引用
	handleQuoteRowData = (rowDate, type) => {
		let { ruleOfReferences } = this.state;
		if (!(rowDate && rowDate.length > 0)) {
			message.error("请选择需要引用数据", this.state.userData && this.state.userData.messageTime);
			return;
		}
		let str = this.handleRuleReference(rowDate, type ? type : ruleOfReferences);
		this.props.handleQuote(str);
	}

	// 其他引用
	handleVitalSignReference = (quoteArr, quoteStr) => {
		this.props.handleQuote(quoteStr, quoteArr);
	}

	// 医嘱引用
	// doctorAdviceQuoteChange = e => {
	// 	this.setState({doctorAdviceQuoteValue: e});
	// }

	// 当前医师
	currentDocChange = e => {
		this.setState({ currentDoc: e.target.checked }, () => {
			this.getHistoryAdmData();
		})
	}

	// 就诊科室
	currentRadioChange = (e) => {
		this.setState({ currentRadio: e.target.value }, () => {
			this.getHistoryAdmData();
		})
	}

	// 就诊类型
	locRadioChange = e => {
		this.setState({ locRadioValue: e.target.value }, () => {
			this.getHistoryAdmData();
		})
	}

	// 获取历史就诊
	getHistoryAdmData = () => {
		this.setState({ loading: true });
		let { historyAdmID, recordData, userData, currentDoc, currentRadio, locRadioValue, historyAdmPageSize, historyAdmPage, treeSelectData, modalRowData } = this.state;
		let data = {
			params: [{
				admID: historyAdmID || recordData.admID,
				currentDoc: currentDoc ? 'Y' : 'N', // 当前医师
				admType: locRadioValue, // 就诊类型
				admLoc: currentRadio === 'currentLocID' ? (userData && userData.locID ? userData.locID : '') : '', // 就诊科室
				power: 'DocEMRHistory',
				catalogueID: treeSelectData.ID, // 分组模板目录ID
				groupTemplateID: modalRowData?.templateID || treeSelectData?.templateID || modalRowData?.ID || '', // 病历模板ID
			}],
			pagination: [{
				pageSize: historyAdmPageSize,
				currentPage: historyAdmPage
			}]
		}
		$http.post('urlS', this, {
			code: '06010069',
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					for (var i = 0; i < res.result.Data.length; i++) {
						res.result.Data[i].key = i;
					}
					this.setState({ historyAdmData: res.result.Data, historyAdmTotal: res.result.totalCount, loading: false });
				} else {
					this.setState({ historyAdmData: [], historyAdmTotal: 0, loading: false })
				}
			}
		})
	}

	handleHistoryAdmPageSizeChange = (current, size) => {
		this.setState({ historyAdmPage: 1, historyAdmPageSize: size }, () => {
			// 重新查询历史就诊数据
			this.getHistoryAdmData();
		})
	}

	handleHistoryAdmPageChange = (page, pageSize) => {
		this.setState({ historyAdmPage: page, historyAdmPageSize: pageSize }, () => {
			// 重新查询历史就诊数据
			this.getHistoryAdmData();
		})
	}

	// 显示病历内容
	showDrawerVisible = (item) => {
		this.setState({ drawerVisible: true, admRowData: item }, () => {
			this.props.compileVNum('noDefault');
			this.getPatienHistoryData();
		})
	}

	// 3.6.8.获取患者病历数据
	getPatienHistoryData = () => {
		let { treeSelectData, modalRowData, admRowData } = this.state;
		let data = {
			params: [{
				admID: admRowData && admRowData.admID ? admRowData.admID : '',
				catalogueID: treeSelectData.ID, // 分组目录ID
				groupTemplateID: modalRowData?.templateID || treeSelectData?.templateID || modalRowData?.ID || '', // 病历模板ID
				power: 'DocEMRHistory',
			}]
		}
		$http.post('urlS', this, {
			code: '06050008',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					// console.log(res.result)
					this.setState({ templatePath: res.result && res.result.templatePath ? res.result.templatePath : '' }, () => {
						this.state.templatePath ? this.caseTemplateChild.setElementTextByID(this.state.templatePath, res.result.dataSource) : this.caseTemplateChild?.NewFile();
					})
				}
			}
		})
	}

	// 隐藏抽屉
	onClose = () => {
		this.setState({
			drawerVisible: false,
		}, () => {
			this.props.compileVNum('default');
		});
	};

	handleCaseTemplateRef = ref => {
		this.caseTemplateChild = ref
	}

	handlePreviewTemplateRef = ref => {
		this.previewTemplateChild = ref;
	}

	loadPreviewTemplate = () => {
		let { previewTemplatePath, previewDataSource } = this.state;
		console.log(previewTemplatePath, previewDataSource, loadPreviewTemplate)
		if (this.previewTemplateChild && this.previewTemplateChild.setElementTextByID) {
			if (previewTemplatePath) {
				setTimeout(() => {
					this.previewTemplateChild.setElementTextByID(previewTemplatePath, previewDataSource)
				}, 800)
			} else {
				this.previewTemplateChild.NewFile();
			}
		} else {
			loadPreviewTemplate++
			if (loadPreviewTemplate < 5) {
				setTimeout(() => {
					this.loadPreviewTemplate()
				}, 300)
			}
		}
	}

	handlePreviewCancel = () => {
		this.setState({ previewVisible: false })
	}

	handlePreviewOk = () => {
		let { knowledgeNodeContent, knowledgeBaseTreeSelectData } = this.state;
		// console.log(knowledgeNodeContent, knowledgeBaseTreeSelectData)
		this.props.setKnowledgeBaseXMl(knowledgeNodeContent, knowledgeBaseTreeSelectData);
	}

	// 右键菜单事件
	handleContextMenu = (record, event) => {
		if (this.root)
			event.preventDefault()

		this.setState({ contextMenuData: record, menuVisible: true })

		// clientX/Y 获取到的是触发点相对于浏览器可视区域左上角距离
		const clickX = event.clientX
		const clickY = event.clientY
		// window.innerWidth/innerHeight 获取的是当前浏览器窗口的视口宽度/高度
		const screenW = window.innerWidth
		const screenH = window.innerHeight
		// 获取自定义菜单的宽度/高度
		const rootW = this.root.offsetWidth
		const rootH = this.root.offsetHeight

		// right为true，说明鼠标点击的位置到浏览器的右边界的宽度可以放下菜单。否则，菜单放到左边。
		// bottom为true，说明鼠标点击位置到浏览器的下边界的高度可以放下菜单。否则，菜单放到上边。
		const right = (screenW - clickX) > rootW
		const left = !right
		const bottom = (screenH - clickY) > rootH
		const top = !bottom

		if (right) {
			this.root.style.left = `${clickX}px`
		}

		if (left) {
			this.root.style.left = `${clickX - rootW}px`
		}

		if (bottom) {
			// console.log('bottom')
			this.root.style.top = `${clickY + 12}px`
		}
		if (top) {
			// console.log('top')
			this.root.style.top = `${clickY - rootH}px`
		}
	};

	// 鼠标单击事件，当鼠标在任何地方单击时，设置菜单不显示
	handleClick = () => {
		const { menuVisible } = this.state
		if (menuVisible) {
			this.setState({ menuVisible: false })
		}
	};

	handleKnowledgeBaseRightClick = ({ event, node }) => {
		let record = node.props && node.props.dataRef ? node.props.dataRef : {};
		// console.log(record)
		// 当右击的节点类型等于目录并且addKnowledgeNode等于Y的话可以新增
		if (record && record.treeType && (record.treeType === 'MAINCATALOG' || record.treeType === 'CATALOG')) {
			if ((record.addKnowledgeNode && !(record.addKnowledgeNode === 'Y' || record.updateOrNot === 'Y' || record.deleteOrNot === 'Y')) || (record.belongs && record.belongs === 'LOC')) {
				//message.error('该目录为科室公共目录，暂不支持修改。');
				//return;
			}
			this.handleContextMenu(record, event);
		} else if (record && record.treeType === 'TEMPLATE') {
			this.handleContextMenu(record, event);
		}
	}

	// 新增知识库目录
	handleAddKnowledge = (type) => {
		let { contextMenuData, userData } = this.state;
		console.log(contextMenuData)
		if (type === 'modifyNode' && !(contextMenuData && contextMenuData.nodeContent)) { // 编辑知识库
			//message.error('（' + contextMenuData.title + '）不是个人知识库，暂不支持修改。')
			//	return;
		}
		this.setState({ knowledgeBaseVisible: true, operationType: type, knowledgeBaseNodeTitle: undefined, nodeContent: undefined }, () => {
			if (this.state.operationType === 'modifyCatalog' || this.state.operationType === 'modifyNode') {
				this.setState({
					knowledgeBaseNodeTitle: contextMenuData && contextMenuData.descripts ? contextMenuData.descripts : undefined,
					nodeContent: this.state.operationType === 'modifyNode' ? (contextMenuData && contextMenuData.nodeContent ? contextMenuData.nodeContent : undefined) : undefined,
				})
			}
			if (this.state.operationType === 'catalog') { // 新增目录
				let locArr = userData && userData.locID ? [userData.locID] : [];
				this.setState({ locArr, KnowledgeBaseTypeValue: '1', })
			}
			if (this.state.operationType === 'modifyCatalog') { // 编辑目录
				let knowlegNodeLocIDs = contextMenuData && contextMenuData.nodeLocIDs ? contextMenuData.nodeLocIDs : []
				this.setState({ locArr: knowlegNodeLocIDs, KnowledgeBaseTypeValue: knowlegNodeLocIDs && knowlegNodeLocIDs.length > 0 ? '2' : '1' })
			}
		})
	}
	// 显示新增目录弹框
	handleAddKnowledgeCatalogShow = () => {
		let { contextMenuData, userData } = this.state;
		let locArr = userData && userData.locID ? [userData.locID] : [];
		this.setState({ showAddKnowledgeCatalog: true, operationType: 'catalog', knowledgeBaseNodeTitle: undefined, locArr, KnowledgeBaseTypeValue: '1', nodeContent: undefined })
	}
	// 隐藏新增目录弹框
	hideAddKnowledgeCatalog = () => {
		this.setState({
			showAddKnowledgeCatalog: false,
		})
	}
	handleAddKnowledgeCatalog = () => {
		let { knowledgeCatalogDesc, knowledgeBaseFiledID, modalRowData } = this.state;
		if ((knowledgeCatalogDesc == "")) {
			message.error("根目录描述不能为空");
			return;
		}
		let data = {
			params: [{
				fieldID: knowledgeBaseFiledID,
				templateVersionID: modalRowData && modalRowData.releaseVersion ? modalRowData.releaseVersion : undefined,
				catalogCode: "USERCUSTOM",
				descripts: knowledgeCatalogDesc,
			}]
		}
		let _this = this;
		$http.post('urlS', this, {
			code: "06020052",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success(res.errorMessage);
					_this.setState({
						knowledgeCatalogDesc: "",
						showAddKnowledgeCatalog: false,
					})
					_this.getKnowledgeBaseTreeData(knowledgeBaseFiledID, modalRowData, "cancel"); // 重新获取目录树
					if (res.ID) {
						_this.saveKnowledge(res.ID);
					}
				}
			}
		})
	}

	saveKnowledge = (knowledgeID) => {
		let { knowledgeBaseNodeTitle, knowledgeBaseFiledID, modalRowData, locArr, KnowledgeBaseTypeValue } = this.state;
		if (!knowledgeBaseNodeTitle) {
			return;
		}
		if (KnowledgeBaseTypeValue == "1") {
			locArr = "";
		}
		let data = {
			params: [{
				// 顶级目录ID 
				knowledgeID: knowledgeID,
				// 新增目录父级ID
				knowlegNodeParID: undefined,
				// 新增知识库父级ID或者编辑知识库父级knowlegNodeID
				knowlegNodeID: undefined,
				// 知识库目录名称
				knowlegNodeDesc: knowledgeBaseNodeTitle,
				knowlegNodeLocIDs: locArr, // 科室选择数据
			}]
		}
		$http.post('urlS', this, {
			code: "06070002",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({ knowledgeBaseNodeTitle: undefined, locArr: [] })
					this.getKnowledgeBaseTreeData(knowledgeBaseFiledID, modalRowData, "cancel"); // 重新获取目录树
				}
			}
		})
	}

	InputValueChange = (code, e) => {
		this.setState({
			[code]: e.target.value
		})
	}

	// 关闭知识库弹窗
	handleKnowledgeBaseCancel = () => {
		this.setState({ knowledgeBaseVisible: false })
	}

	// 保存知识库目录 catalog -- 新增目录  node -- 新增知识库  modifyNode -- 编辑知识库   modifyCatalog --- 修改目录
	handleKnowledgeBaseSave = () => {
		let { knowledgeBaseNodeTitle, contextMenuData, knowledgeBaseFiledID, modalRowData, nodeContent, operationType, knowledgeBaseTreeData, locArr, KnowledgeBaseTypeValue } = this.state;
		let topLevelDirectoryID = knowledgeBaseTreeData && knowledgeBaseTreeData.length > 0 ? knowledgeBaseTreeData[0].ID : undefined; // 顶级目录ID
		// console.log(knowledgeBaseNodeTitle, contextMenuData)
		if (!knowledgeBaseNodeTitle) {
			let msgTitle = (operationType === "node" || operationType === "modifyNode") ? "知识库不能为空" : "知识库目录不能为空";
			message.error(msgTitle);
			return;
		}
		if ((operationType === "node" || operationType === "modifyNode") && !nodeContent) {
			message.error("知识库内容不能为空。");
			return;
		}
		if (KnowledgeBaseTypeValue == "1") {
			locArr = "";
		}
		let data = {
			params: [{
				// 顶级目录ID 
				knowledgeID: (operationType === "catalog" && contextMenuData && contextMenuData.treeType === "MAINCATALOG") ?
					(contextMenuData && contextMenuData.ID ? contextMenuData.ID : "") : (contextMenuData && contextMenuData.treeType === "CATALOG" ? topLevelDirectoryID : undefined),
				// 新增目录父级ID
				knowlegNodeParID: operationType === "catalog" && contextMenuData && contextMenuData.treeType === "CATALOG" ? (contextMenuData.ID ? contextMenuData.ID : undefined) : (operationType === "modifyCatalog" && contextMenuData.treeType === "CATALOG" ? contextMenuData.knowlegNodeParID : undefined),
				// 新增知识库父级ID或者编辑知识库父级knowlegNodeID
				knowlegNodeID: (operationType === "node" || operationType === "modifyCatalog") ?
					(contextMenuData && contextMenuData.ID ? contextMenuData.ID : undefined) :
					(operationType === "catalog" ? undefined : (contextMenuData && contextMenuData.knowlegNodeID ? contextMenuData.knowlegNodeID : undefined)),
				// 知识库目录名称
				knowlegNodeDesc: (operationType === "node" || operationType === "modifyNode") ? undefined : knowledgeBaseNodeTitle,

				// 知识库节点名称
				nodeDataDesc: (operationType === "node" || operationType === "modifyNode") ? knowledgeBaseNodeTitle : undefined,
				// 知识库节点编辑ID
				nodeDataID: operationType === "modifyNode" ? (contextMenuData && contextMenuData.ID ? contextMenuData.ID : "") : undefined,
				// 知识库内容
				nodeContent: operationType === "catalog" ? undefined : nodeContent,
				knowlegNodeLocIDs: (operationType === "catalog" || operationType === "modifyCatalog") ? locArr : undefined, // 科室选择数据
			}]
		}
		$http.post('urlS', this, {
			code: (operationType === "catalog" || operationType === "modifyCatalog") ? "06070002" : "06070003",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success(res.errorMessage);
					this.setState({ knowledgeBaseNodeTitle: undefined, locArr: [] }, () => {

					})
					this.handleKnowledgeBaseCancel();
					this.getKnowledgeBaseTreeData(knowledgeBaseFiledID, modalRowData, "cancel"); // 重新获取目录树
				}
			}
		})
	}

	// 知识库节点名称change
	handleKnowledgeBaseNodeTitleChange = e => {
		this.setState({ knowledgeBaseNodeTitle: e.target.value })
	}

	// 知识库内容维护
	handleNodeContentChange = e => {
		this.setState({ nodeContent: e.target.value })
	}

	// 展开操作
	onExpand = (expandedKeys) => {
		// console.log("触发了onExpand", expandedKeys)
		this.setState({
			expandedKeys,
			autoExpandParent: false,
		});
	}

	// 删除知识库节点目录
	handleDeleteNodeDirectory = () => {
		let { contextMenuData, userData, knowledgeBaseFiledID, modalRowData } = this.state;
		let code = '';
		if (contextMenuData && contextMenuData.ID) {
			if (contextMenuData.treeType === 'CATALOG') {
				code = '06020022';
			} else if (contextMenuData.treeType === 'TEMPLATE') {
				code = '06020029';
			}
			else {
				message.warn('不允许删除主目录');
				return;
			}
		} else {
			return;
		}
		let data = {
			params: [{
				belongsUserID: userData && userData.userID ? userData.userID : "",
				ID: contextMenuData.ID,
				power: "foreven"
			}]
		}
		$http.post('urlADS', this, {
			code: code,
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success('删除成功');
					// 刷新列表数据
					this.getKnowledgeBaseTreeData(knowledgeBaseFiledID, modalRowData, "cancel"); // 重新获取目录树
				}
			}
		})
	}

	// 知识库类型
	handleKnowledgeBaseTypeChange = e => {
		let { userData, locArr } = this.state;
		this.setState({ KnowledgeBaseTypeValue: e }, () => {
			if (this.state.KnowledgeBaseTypeValue === "2" && locArr && locArr.length < 1) {
				let locArr = userData && userData.locID ? [userData.locID] : [];
				this.setState({ locArr })
			}
		})
	}

	// 获取科室下拉列表
	getLocSelectData = () => {
		let { userData } = this.state;
		let data = {
			params: [{
				hospID: userData && userData.hospID ? userData.hospID : ""
			}]
		}
		$http.post('urlS', this, {
			code: "04020008",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({ locSelectData: res.result.Data })
				} else {
					this.setState({ locSelectData: [] })
				}
			}
		})
	}

	// 科室
	handleLocChange = e => {
		this.setState({ locArr: e })
	}

	// 判断是字符串还是xml
	handleDetermineWhetherItIsXML = (str) => {
		return str.indexOf("<XTextDocument") !== -1;
	}

	render() {
		let { tabsData, tabsActiveKey, doctorAdviceColumns, doctorAdviceTableData, doctorAdviceRowKeys, doctorAdviceRows, doctorAdviceWidth, radioValue, previewVisible,
			historyVisible, historyADMTableData, doctorAdviceHistoryColumns, doctorAdviceHistoryRowKeys, radioButtonValue, inspectTableData, inspectColumns,
			inspectWidth, inspectRowKeys, inspectRows, doctorAdviceRadioData, testColumns, testTableData, testWidth, testRowKeys, testRows, chineseHerbalMedicineColumns, chineseHerbalMedicineTableData,
			chineseHerbalMedicineWidth, chineseHerbalMedicineRowKeys, inspectRadioValue, insertMethod,
			inspectionRadioValue, historyAdmID, pathologicalTableData, pathologicalColumns, pathologicalWidth, pathologicalRowKeys, historyPage,
			historyTotal, loading, doctorAdvicePage, doctorAdviceTotal, inspectPage, inspectTotal, testPage, testTotal, pathologicalPage, pathologicalTotal,
			chineseHerbalMedicinePage, chineseHerbalMedicineTotal, vitalSignsPage, vitalSignsTotal, inspectDetailTableData, inspectDetailWidth, drawerVisible,
			testDetailColumns, testDetailTableData, testDetailWidth, inspectionFindingsCheck, diagnosticOpinionCheck, inspectionMethod, knowledgeBaseSelectedKeys,
			knowledgeBaseTreeData, currentRadio, locRadioValue, currentDoc, historyAdmData, historyAdmTotal, historyAdmPage, chineseHerbalMedicineRowData, doctorAdviceHistoryWidth,
			menuVisible, knowledgeBaseVisible, contextMenuData, knowledgeBaseNodeTitle, nodeContent, operationType, autoExpandParent, expandedKeys, KnowledgeBaseTypeValue, knowledgeBaseTypeData,
			locArr, locSelectData
		} = this.state;
		const doctorAdviceRowSelection = { // 医嘱
			selectedRowKeys: doctorAdviceRowKeys,
			selectedRows: doctorAdviceRows,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({ doctorAdviceRowKeys: selectedRowKeys, doctorAdviceRows: selectedRows })
			},
			onSelectAll: (selected, selectedRows, changeRows) => {
				this.setState({ doctorAdviceRows: selectedRows })
			},
		};

		const doctorAdviceHistoryRowSelection = { // 引用历史就诊
			selectedRowKeys: doctorAdviceHistoryRowKeys,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({ doctorAdviceHistoryRowKeys: selectedRowKeys })
			}
		};

		const inspectRowSelection = { // 检查
			selectedRowKeys: inspectRowKeys,
			selectedRows: inspectRows,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({ inspectRowKeys: selectedRowKeys, inspectRows: selectedRows })
			},
			onSelectAll: (selected, selectedRows, changeRows) => {
				this.setState({ inspectRows: selectedRows })
			},
		}

		const testRowSelection = { // 检验
			selectedRowKeys: testRowKeys,
			selectedRows: testRows,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({ testRowKeys: selectedRowKeys, testRows: selectedRows })
			},
			onSelectAll: (selected, selectedRows, changeRows) => {
				this.setState({ testRows: selectedRows })
			},
		}

		const chineseHerbalMedicineRowSelection = { // 中草药
			selectedRowKeys: chineseHerbalMedicineRowKeys,
			selectedRows: chineseHerbalMedicineRowData,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({ chineseHerbalMedicineRowKeys: selectedRowKeys, chineseHerbalMedicineRowData: selectedRows })
			},
			onSelectAll: (selected, selectedRows, changeRows) => {
				this.setState({ chineseHerbalMedicineRowData: selectedRows })
			},
		}

		// const vitalSignsRowSelection = { // 生命体征
		// 	selectedRowKeys: vitalSignsRowKeys,
		// 	onChange: (selectedRowKeys, selectedRows) => {
		// 		this.setState({ vitalSignsRowKeys: selectedRowKeys })
		// 	},
		// }

		const pathologicalRowSelection = { // 病理
			selectedRowKeys: pathologicalRowKeys,
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({ pathologicalRowKeys: selectedRowKeys })
			},
		}


		let inspectDetailColumns = [
			{
				title: () => {
					return (
						<div>
							<Checkbox checked={inspectionFindingsCheck} onChange={this.inspectionFindingsChange}>
								检查所见
							</Checkbox>
						</div>
					)
				},
				dataIndex: 'CancelExecStatus',
				key: 1,
				align: "center",
			},
			{
				title: () => {
					return (
						<div>
							<Checkbox checked={diagnosticOpinionCheck} onChange={this.diagnosticOpinionCheckChange}>
								诊断意见
							</Checkbox>
						</div>
					)
				},
				dataIndex: 'states',
				key: 2,
				align: "center",
			},
			{
				title: () => {
					return (
						<div>
							<Checkbox checked={inspectionMethod} onChange={this.inspectionMethodChange}>
								检查方法
							</Checkbox>
						</div>
					)
				},
				dataIndex: 'states',
				key: 3,
				align: "center",
			},
		]

		let radioDom = (
			<Radio.Group onChange={this.radioChange} value={radioValue}>
				<Radio value="1">本次就诊</Radio>
				<Radio value="2" onClick={this.handleRadioClick}>选择就诊</Radio>
			</Radio.Group>
		)

		let radioButtom = (
			<Radio.Group onChange={this.radioButtonChange} value={radioButtonValue}>
				{doctorAdviceRadioData && doctorAdviceRadioData.map((item, index) => {
					return (
						<Radio.Button value={item.code} key={index}>{item.descripts}</Radio.Button>
					)
				})}
			</Radio.Group>
		)

		// 知识库 --- knowledgeBase
		let knowledgeBaseDom = (
			<div>
				{/* <div style={{ height: "100%", overflow: 'auto', padding: "12px 0 0 12px" }}> */}
				<div style={{ height: this.props.showOnly && this.props.showOnly === "knowledgeBase" ? (previewVisible ? store.getState().tableHeight.y - 356 : store.getState().tableHeight.y - 86) : (previewVisible ? store.getState().tableHeight.y - 182 : store.getState().tableHeight.y + 88), overflow: 'auto', padding: "12px 0 0 12px" }}>
					{knowledgeBaseTreeData && knowledgeBaseTreeData.length > 0 ? <Tree showIcon
						onSelect={this.knowledgeBaseOnSelect}
						selectedKeys={knowledgeBaseSelectedKeys}
						autoExpandParent={autoExpandParent}
						onExpand={this.onExpand}
						expandedKeys={expandedKeys}
						onDoubleClick={this.knowledgeBaseDoubleClick}
						onRightClick={this.handleKnowledgeBaseRightClick}
					>
						{this.renderTreeNodes(knowledgeBaseTreeData)}
					</Tree> : "暂无数据"}
				</div>
				<div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%', display: previewVisible ? "block" : "none" }}></div>

				{previewVisible ? <Card
					size="small"
					title={<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
						<div className="card-title-left-icon">
							<div></div>
							知识库预览{contextMenuData && contextMenuData.title ? ("（" + contextMenuData.title + "）") : ""}
						</div>
						<div onClick={this.handlePreviewCancel} style={{ fontSize: "12px", cursor: "pointer", color: "red" }}>关闭</div>
					</div>}
				>
					<div style={{ height: "200px", overflow: 'auto' }}>
						<KnowledgeBasePreviewTemplate
							onRef={this.handlePreviewTemplateRef}
							handleReload={this.loadPreviewTemplate}
						/>
					</div>
				</Card> : ""}
			</div>
		)

		// 医嘱 --- QuoteResourcesOrder
		let doctorAdviceDom = (
			<div>
				<div style={{ lineHeight: '36px', padding: '0 8px', display: 'flex', flexWrap: 'wrap', margin: '8px 0', justifyContent: 'space-between' }}>
					<div>
						{radioDom}
					</div>
					<div>
						{radioButtom}
					</div>
				</div>
				<Table
					className="table-body"
					rowSelection={doctorAdviceRowSelection}
					columns={doctorAdviceColumns}
					dataSource={doctorAdviceTableData}
					bordered
					pagination={false}
					scroll={{ x: doctorAdviceWidth, y: store.getState().tableHeight.y - 116 }}
				/>
				<CommonPagination
					size="small"
					current={doctorAdvicePage}
					total={doctorAdviceTotal}
					search='search'
					onShowSizeChange={this.handleDoctorAdvicePageSizeChange}
					complete={false}
					dataSource={doctorAdviceTableData}
					loading={loading}
					onChange={this.handleDoctorAdvicePageChange}
				/>
				<div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
				<div style={{ textAlign: 'center', paddingTop: '6px' }}>
					{/* 引用方式：<Select value={doctorAdviceQuoteValue} onChange={this.doctorAdviceQuoteChange} style={{width: '150px', marginRight: "20px"}}>
						<Option value="ordDate+ordTime+medDesc+ordFreqDesc+ordDoseUnitDesc">时间+名称+剂量+单位</Option>
					</Select> */}
					排序方式：
					<Select
						style={{ width: '100px', marginRight: '12px' }}
						value={insertMethod}
						placeholder="请选择"
						onChange={Util.handleSelectChange.bind(this, 'insertMethod')}
					>
						<Option key="1" value="transverse" title="横排">横排</Option>
						<Option key="2" value="vertical" title="竖排">竖排</Option>
					</Select>
					<Button type="primary" onClick={() => this.handleQuoteRowData(doctorAdviceRows)}>引用</Button>
				</div>
			</div>
		)

		// 检查 --- EMRCitingResourcesExamine
		let inspectDom = (
			<div>
				<div style={{ paddingLeft: '8px' }}>
					<Radio.Group onChange={this.inspectRadioChange} value={inspectRadioValue}>
						<Radio value="currentDay">当日</Radio>
						<Radio value="threeDay">三日内</Radio>
						<Radio value="fiveDay">五日内</Radio>
						<Radio value="sevenDay">七日内</Radio>
						<Radio value="currentWeek">本周</Radio>
						<Radio value="noExamReport">未报告</Radio>
					</Radio.Group>
				</div>
				<div style={{ lineHeight: "40px", padding: "0 8px" }}>
					{radioDom}
				</div>
				<Table
					style={{ height: store.getState().tableHeight.y / 2 - 5 + 'px' }}
					rowSelection={inspectRowSelection}
					columns={inspectColumns}
					dataSource={inspectTableData}
					bordered
					pagination={false}
					className="table-body"
					scroll={{ x: inspectWidth, y: store.getState().tableHeight.y / 2 - 50 }}
				/>
				<CommonPagination
					size="small"
					current={inspectPage}
					total={inspectTotal}
					search='search'
					onShowSizeChange={this.handleInspectPageSizeChange}
					complete={false}
					dataSource={inspectTableData}
					loading={loading}
					onChange={this.handleInspectPageChange}
				/>
				<Table
					style={{ height: store.getState().tableHeight.y / 2 - 38 + 'px' }}
					columns={inspectDetailColumns}
					dataSource={inspectDetailTableData}
					bordered
					pagination={false}
					scroll={{ x: inspectDetailWidth, y: store.getState().tableHeight.y / 2 - 38 }}
				/>
				<div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
				<div style={{ textAlign: 'right', lineHeight: '40px' }}>
					<Button type="primary" onClick={() => this.handleQuoteRowData(inspectRows, "medDesc")}>引用</Button>
				</div>
			</div>
		)

		// 检验 --- EMRCitingResourcesInspection
		let inspectionDom = (
			<div>
				<div style={{ paddingLeft: '8px' }}>
					<Radio.Group onChange={this.inspectionRadioChange} value={inspectionRadioValue}>
						<Radio value="currentDay">当日</Radio>
						<Radio value="threeDay">三日内</Radio>
						<Radio value="fiveDay">五日内</Radio>
						<Radio value="sevenDay">七日内</Radio>
						<Radio value="currentWeek">本周</Radio>
						<Radio value="noAudit">未审核</Radio>
					</Radio.Group>
				</div>
				<div style={{ lineHeight: '40px', padding: '0 8px' }}>
					{radioDom}
				</div>
				<Table
					style={{ height: store.getState().tableHeight.y / 2 - 5 + 'px' }}
					rowSelection={testRowSelection}
					columns={testColumns}
					dataSource={testTableData}
					bordered
					className="table-body"
					pagination={false}
					scroll={{ x: testWidth, y: store.getState().tableHeight.y / 2 - 50 }}
				/>
				<CommonPagination
					size="small"
					current={testPage}
					total={testTotal}
					search='search'
					onShowSizeChange={this.handleTestPageSizeChange}
					complete={false}
					dataSource={testTableData}
					loading={loading}
					onChange={this.handleTestPageChange}
				/>
				<Table
					style={{ height: store.getState().tableHeight.y / 2 - 38 + "px" }}
					columns={testDetailColumns}
					dataSource={testDetailTableData}
					bordered
					pagination={false}
					scroll={{ x: testDetailWidth, y: store.getState().tableHeight.y / 2 - 38 }}
				/>
				<div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
				<div style={{ textAlign: 'right', lineHeight: "40px" }}>
					<Button type="primary" onClick={() => this.handleQuoteRowData(testRows, "medDesc")}>引用</Button>
				</div>
			</div>
		)

		// 病理 --- EMRCitingResourcesPathological
		let pathologicalReportDom = (
			<div>
				<div style={{ lineHeight: '40px', paddingLeft: '8px' }}>
					{radioDom}
				</div>
				<Table
					style={{ minHeight: '230px' }}
					rowSelection={pathologicalRowSelection}
					columns={pathologicalColumns}
					dataSource={pathologicalTableData}
					bordered
					pagination={false}
					scroll={{ x: pathologicalWidth, y: store.getState().tableHeight.y + 8 }}
				/>
				<CommonPagination
					size="small"
					current={pathologicalPage}
					total={pathologicalTotal}
					search='search'
					onShowSizeChange={this.handlePathologicalPageSizeChange}
					complete={false}
					dataSource={pathologicalTableData}
					loading={loading}
					onChange={this.handlePathologicalPageChange}
				/>
			</div>
		)

		// 中草药 -- EMRCitingResourcesCMMed
		let chineseHerbalMedicineDom = (
			<div>
				<div style={{ lineHeight: '40px', padding: '0 8px' }}>
					{radioDom}
				</div>
				<Table
					className="table-body"
					rowSelection={chineseHerbalMedicineRowSelection}
					columns={chineseHerbalMedicineColumns}
					dataSource={chineseHerbalMedicineTableData}
					bordered
					pagination={false}
					scroll={{ x: chineseHerbalMedicineWidth, y: store.getState().tableHeight.y - 68 }}
				/>
				<CommonPagination
					size="small"
					current={chineseHerbalMedicinePage}
					total={chineseHerbalMedicineTotal}
					search='search'
					onShowSizeChange={this.handleChineseHerbalMedicinePageSizeChange}
					complete={false}
					dataSource={chineseHerbalMedicineTableData}
					loading={loading}
					onChange={this.handleChineseHerbalMedicinePageChange}
				/>
				<div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
				<div style={{ textAlign: 'right', lineHeight: "40px" }}>
					{/* 引用方式：<Select value={chineseHerbalMedicineValue} onChange={this.chineseHerbalMedicineChange} style={{width: '150px', marginRight: "20px"}}>
						<Option value="ordStopDate+medDesc+ordFreqDesc+ordDoseUnitDesc">时间+名称+剂量+单位</Option>
					</Select> */}
					<Button type="primary" onClick={() => this.handleQuoteRowData(chineseHerbalMedicineRowData)}>引用</Button>
				</div>
			</div>
		)

		// 生命体征 --- EMRCitingResourcesTemperature
		// let vitalSignsDom = (
		// 	<div>
		// 		<div style={{ padding: "0 8px" }}>
		// 			<Radio.Group onChange={this.vitalSignsRadioChange} value={vitalSignsRadioValue}>
		// 				<Radio value="currentDay">当日</Radio>
		// 				<Radio value="threeDay">三日内</Radio>
		// 				<Radio value="fiveDay">五日内</Radio>
		// 				<Radio value="sevenDay">七日内</Radio>
		// 				<Radio value="currentWeek">本周</Radio>
		// 				<Radio value="currentAdm">本次就诊</Radio>
		// 			</Radio.Group>
		// 		</div>
		// 		<div style={{ lineHeight: "40px", padding: "0 8px" }}>
		// 			{radioDom}
		// 		</div>
		// 		<Table
		// 			className="table-body"
		// 			rowSelection={vitalSignsRowSelection}
		// 			columns={vitalSignsColumns}
		// 			dataSource={vitalSignsTableData}
		// 			bordered
		// 			// pagination={false}
		// 			scroll={{ x: vitalSignsWidth, y: store.getState().tableHeight.y - 82 }}
		// 		/>
		// 		<CommonPagination
		// 			size="small"
		// 			current={vitalSignsPage}
		// 			total={vitalSignsTotal}
		// 			search='search'
		// 			onShowSizeChange={this.handleVitalSignsPageSizeChange}
		// 			complete={false}
		// 			dataSource={vitalSignsTableData}
		// 			loading={loading}
		// 			onChange={this.handleVitalSignsPageChange}
		// 		/>
		// 		<div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
		// 		<div style={{ textAlign: 'right', lineHeight: "40px" }}>
		// 			<Button type="primary">引用</Button>
		// 		</div>
		// 	</div>
		// )

		// 专科知识库 --- SpecializedKnowledgeBase
		let specializedKnowledgeBaseDom = (
			<div>
				专科知识库
			</div>
		)

		// let param = {
		// 	isBasicOperation: true,
		// 	isFont: true,
		// 	isInsert: "hidden",
		// 	domId: "mydetailWriterControl"
		// }

		// 历史就诊 --- EMRCitingHistoryAdm
		let historyAdm = (
			<div style={{ position: 'relative' }}>
				<div style={{ padding: '12px', borderBottom: '1px solid #e8e8e8' }}>
					<div style={{ display: 'inline-block', lineHeight: '24px', marginRight: '24px' }}>
						<Checkbox onChange={this.currentDocChange} checked={currentDoc} style={{ marginRight: '24px' }}>当前医生</Checkbox>
						<Radio.Group onChange={this.currentRadioChange} value={currentRadio}>
							<Radio value="currentLocID">当前科室</Radio>
							<Radio value="ALLHosp">全院</Radio>
						</Radio.Group>
					</div>
					<div style={{ display: 'inline-block', lineHeight: "24px" }}>
						<Radio.Group onChange={this.locRadioChange} value={locRadioValue}>
							<Radio value="O">门诊</Radio>
							<Radio value="EM">急诊</Radio>
							<Radio value="I">住院</Radio>
							<Radio value="ALL">全部</Radio>
						</Radio.Group>
					</div>
				</div>
				<div style={{ height: store.getState().tableHeight.y - (drawerVisible ? -20 : 28), overflow: 'auto' }}>
					{historyAdmData && historyAdmData.length > 0 ? historyAdmData.map((item, index) => {
						return (
							<div key={index} style={{ borderBottom: '1px solid #e8e8e8', padding: '0 12px' }}>
								<div>
									<span>
										{item.admDate}
									</span>

								</div>
								<div style={{ textAlign: 'right' }}>
									<span style={{ marginRight: '8px' }}>
										{item.admLocDesc}
									</span>
									<span>
										{item.admDocDesc}
									</span>
								</div>
								<div style={{ textAlign: 'right', fontSize: '12px' }}>
									<span style={{ marginRight: '8px', cursor: 'pointer', color: 'red', display: item && item.sameHisEMRFlag === 'Y' ? 'inline-block' : 'none' }}
										onClick={() => this.showDrawerVisible(item)}>
										病历内容...
									</span>
									{/* <span style={{ cursor: 'pointer', color: 'red' }}>医嘱内容...</span> */}
								</div>
							</div>
						)
					}) : <div style={{ padding: '12px 0 0 12px' }}>暂无数据</div>}
				</div>
				<CommonPagination
					size="small"
					current={historyAdmPage}
					total={historyAdmTotal}
					search='search'
					onShowSizeChange={this.handleHistoryAdmPageSizeChange}
					complete={false}
					dataSource={historyAdmData}
					loading={loading}
					onChange={this.handleHistoryAdmPageChange}
				/>
				<Drawer
					title="病历内容"
					placement="right"
					closable={true}
					onClose={this.onClose}
					visible={drawerVisible}
					getContainer={false}
					width="100%"
					className="case-information-drawer"
					style={{ position: 'absolute' }}
				>
					<div style={{ width: "100%", height: store.getState().tableHeight.y + 60 }}>
						<DetailMedicalRecordTemplate
							onRef={this.handleCaseTemplateRef}
							handleReload={this.getPatienHistoryData}
						/>
					</div>
				</Drawer>
			</div>
		)

		let knowledgeBaseTypeOption = knowledgeBaseTypeData && knowledgeBaseTypeData.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 科室
		var locOption = []
		locSelectData && locSelectData.map((item, index) => {
			locOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id} seatchprop={item.descripts + '^' + item.descriptsSPCode} title={item.descripts}>{item.descripts}</Option>)
		})

		return (
			<div style={{ height: '100%' }} className="case-information-page-tabs">
				<Tabs
					className="right-tabs"
					activeKey={tabsActiveKey}
					onChange={this.handleTabsChange}
					style={{
						height: '100%', overflow: 'auto',
						display: this.props.showOnly && this.props.showOnly === 'knowledgeBase' ? 'none' : 'block'
					}}
					tabBarExtraContent={(
						this.props.hideTabs ? ((this.props.showOnly && this.props.showOnly === 'knowledgeBase') ? '' : (
							<Tooltip placement="topRight" title="点击此处隐藏引用页签">
								<span style={{ paddingRight: '4px' }}>
									<Icon type="double-right" className="common-card-hide-icon common-card-show-icon" style={{ fontSize: '15px' }} onClick={this.props.hideTabs} />
								</span>
							</Tooltip>
						)) : ''
					)}
				>
					{tabsData && tabsData.map((item, index) => {
						return (
							<TabPane tab={item.descripts} key={item.code}>
								{item.code === "knowledgeBase" ? knowledgeBaseDom :
									(item.code === "EMRCitingResourcesInspection" ? inspectionDom :
										(item.code === "EMRCitingResourcesExamine" ? inspectDom :
											(item.code === "EMRCitingResourcesPathological" ? pathologicalReportDom :
												(item.code === "QuoteResourcesOrder" ? doctorAdviceDom :
													(item.code === "EMRCitingResourcesCMMed" ? chineseHerbalMedicineDom :
														(item.code === "EMRCitingResourcesTemperature" ? <EMRVitalSigns historyAdmID={historyAdmID} handleQuote={this.handleVitalSignReference} /> :
															(item.code === "SpecializedKnowledgeBase" ? specializedKnowledgeBaseDom :
																(item.code === "EMRCitingHistoryAdm" ? historyAdm : ""))))))))}
							</TabPane>
						)
					})}
				</Tabs>

				<Tabs
					activeKey="1"
					style={{
						height: '100%', overflow: 'auto',
						display: this.props.showOnly && this.props.showOnly === 'knowledgeBase' ? 'block' : 'none'
					}}
					tabBarExtraContent={(
						this.props.hideTabs ? ((this.props.showOnly && this.props.showOnly === 'knowledgeBase') ? '' : (
							<Tooltip placement="topRight" title="点击此处隐藏引用页签">
								<span style={{ paddingRight: '4px' }}>
									<Icon type="double-right" className="common-card-hide-icon common-card-show-icon" style={{ fontSize: '15px' }} onClick={this.props.hideTabs} />
								</span>
							</Tooltip>
						)) : ''
					)}
				>
					<TabPane tab="知识库" key="1">
						{knowledgeBaseDom}
					</TabPane>
				</Tabs>

				<div ref={(ref) => { this.root = ref }} className="contextMenu-wrap" style={{ visibility: menuVisible ? 'visible' : 'hidden' }}>
					<div className="contextMenu-option"
						onClick={() => this.handleAddKnowledgeCatalogShow()}
						style={{ display: contextMenuData.treeType === "MAINCATALOG" ? "block" : 'none' }}
					>新增节点目录</div>
					<div className="contextMenu-option"
						onClick={() => this.handleAddKnowledge("catalog")}
						style={{ display: contextMenuData && contextMenuData.addKnowledgeNode && contextMenuData.addKnowledgeNode === "Y" && contextMenuData.belongs && contextMenuData.belongs === "USER" && contextMenuData.treeType && (contextMenuData.treeType === "MAINCATALOG" || contextMenuData.treeType === "CATALOG") ? "block" : "none" }}
					>新增知识库目录</div>
					<div className="contextMenu-option"
						onClick={() => this.handleAddKnowledge("node")}
						style={{ display: contextMenuData && contextMenuData.addOrNot && contextMenuData.addOrNot === "Y" && contextMenuData.belongs && contextMenuData.belongs === "USER" && contextMenuData.treeType && contextMenuData.treeType === "CATALOG" ? "block" : "none" }}
					>新增知识库</div>
					<div className="contextMenu-option"
						onClick={() => this.handleAddKnowledge("modifyCatalog")}
						style={{
							display:
								contextMenuData && contextMenuData.treeType && contextMenuData.belongs && contextMenuData.belongs === "USER" &&
									(contextMenuData.treeType === "CATALOG") && (contextMenuData.code != "COMMON") &&
									(contextMenuData.updateKnowledgeNode === "Y" || contextMenuData.addKnowledgeNode === "Y") ? "block" : "none"
						}}
					>编辑知识库目录</div>
					<div className="contextMenu-option"
						onClick={() => this.handleAddKnowledge("modifyNode")}
						style={{
							display: contextMenuData && contextMenuData.treeType && contextMenuData.treeType === "TEMPLATE" && contextMenuData.belongs &&
								contextMenuData.belongs === "USER" && (contextMenuData.addOrNot === "Y" || contextMenuData.updateOrNot === "Y") &&
								!this.handleDetermineWhetherItIsXML(contextMenuData.nodeContent) ? "block" : "none"
						}}
					>编辑知识库</div>
					<div className="contextMenu-option"
						onClick={this.handleTreeNodesClick}
						style={{ display: contextMenuData && contextMenuData.treeType && contextMenuData.treeType === "TEMPLATE" && this.handleDetermineWhetherItIsXML(contextMenuData.nodeContent) ? "block" : "none" }}
					>预览知识库</div>
					<Popconfirm title="删除不可恢复，你确定要删除吗?" onConfirm={this.handleDeleteNodeDirectory}>
						<div className="contextMenu-option"
							style={{ display: contextMenuData && contextMenuData.treeType && contextMenuData.belongs && contextMenuData.belongs === "USER" && contextMenuData.deleteOrNot === "Y" && contextMenuData.treeType != "MAINCATALOG" ? "block" : "none" }} //  && contextMenuData.treeType === "TEMPLATE"
						>{contextMenuData && contextMenuData.treeType === "MAINCATALOG" ? "删除主目录" : (contextMenuData.treeType === "CATALOG" ? "删除目录" : "删除节点")}</div>
					</Popconfirm>
				</div>

				<ColumnAuthoritysModel
					clientWidth='800px'
					compontName={this.state.tabsActiveKey}
					configType="C"
					onRef={this.onDoctorAdviceColumnRef}
					reloadData={() => this.getDoctorAdviceColumns()}
				/>

				<ColumnAuthoritysModel
					clientWidth='800px'
					compontName='EMRCitingResourcesHistoryAdm'
					configType="C"
					onRef={this.onDoctorAdviceHistoryColumnRef}
					reloadData={() => this.getDoctorAdviceColumns("EMRCitingResourcesHistoryAdm")}
				/>

				<ColumnAuthoritysModel
					clientWidth='800px'
					compontName='EMRCitingResourcesInspectSub'
					configType="C"
					onRef={this.onDetailColumnRef}
					reloadData={() => this.getDetailColumns("EMRCitingResourcesInspectSub")}
				/>

				<Modal
					title="历史就诊记录"
					visible={historyVisible}
					onOk={this.handleHistoryOk}
					onCancel={this.handleHistoryCancel}
					style={{ minWidth: '680px' }}
					className="madal-body-height"
				>
					<Table
						rowSelection={doctorAdviceHistoryRowSelection}
						columns={doctorAdviceHistoryColumns}
						bordered
						dataSource={historyADMTableData}
						pagination={false}
						className="table-body"
						scroll={{ x: doctorAdviceHistoryWidth, y: 380 }}
					/>
					<CommonPagination
						size="small"
						current={historyPage}
						total={historyTotal}
						search='search'
						onShowSizeChange={this.handleHistoryPageSizeChange}
						complete={false}
						dataSource={historyADMTableData}
						loading={loading}
						onChange={this.handleHistoryPageChange}
					/>
				</Modal>
				<Modal
					title={operationType === "node" ? "新增知识库" : (operationType === "catalog" ? "新增知识库目录" : (operationType === "modifyNode" ? "编辑知识库" : "编辑目录"))}
					visible={knowledgeBaseVisible}
					onCancel={this.handleKnowledgeBaseCancel}
					style={{ minWidth: '800px', minHeight: '600px' }}
					onOk={this.handleKnowledgeBaseSave}
					okText="保存"
				>
					<div>
						<div style={{
							display: (operationType === "node" || operationType === "modifyNode") ? "none" : "block"
						}}>
							<div className="formRequired" style={{ height: "32px", position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>
								知识库类型：
							</div>
							<Select onChange={this.handleKnowledgeBaseTypeChange} value={KnowledgeBaseTypeValue} placeholder="请选择" style={{ width: "100%", marginBottom: "12px" }}>
								{knowledgeBaseTypeOption}
							</Select>
						</div>
						<div style={{
							display: (!(operationType === "node" || operationType === "modifyNode")) && (KnowledgeBaseTypeValue === "2") ? "block" : "none"
						}}>
							<div className="formRequired" style={{ height: "32px", position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>
								科室：
							</div>
							<Select mode="multiple" onChange={this.handleLocChange} value={locArr} placeholder="请选择" style={{ width: "100%", marginBottom: "12px" }}>
								{locOption}
							</Select>
						</div>
						<div className="formRequired" style={{ height: "32px", position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>
							{operationType === "node" || operationType === "modifyNode" ? "知识库名称" : "知识库目录名称"}：
						</div>
						<Input placeholder="请输入" value={knowledgeBaseNodeTitle} onChange={this.handleKnowledgeBaseNodeTitleChange} />
						<div style={{
							display: (operationType === "node" || operationType === "modifyNode") ? "block" : "none"
						}}>
							<div className="formRequired" style={{ height: "32px", marginTop: '12px', position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>
								知识库内容：
							</div>
							<TextArea rows={4} value={nodeContent} onChange={this.handleNodeContentChange} />
						</div>
					</div>
				</Modal>
				<Modal
					title="新增节点目录&知识库目录"
					visible={this.state.showAddKnowledgeCatalog}
					onCancel={this.hideAddKnowledgeCatalog}
					// footer={null}
					onOk={this.handleAddKnowledgeCatalog}
					style={{ minWidth: '600px' }}
				>
					<div style={{ display: "block" }}>
						<div className="formRequired" style={{ height: "32px", marginTop: '12px', position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>节点目录描述</div>
						<Input value={this.state.knowledgeCatalogDesc} onChange={this.InputValueChange.bind(this, "knowledgeCatalogDesc")} placeholder="请输入" />
					</div>
					<div style={{
						display: (operationType === "node" || operationType === "modifyNode") ? "none" : "block"
					}}>
						<div className="" style={{ height: "32px", position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>知识库类型：</div>
						<Select onChange={this.handleKnowledgeBaseTypeChange} value={KnowledgeBaseTypeValue} placeholder="请选择" style={{ width: "100%", marginBottom: "12px" }}>
							{knowledgeBaseTypeOption}
						</Select>
					</div>
					<div style={{
						display: (!(operationType === "node" || operationType === "modifyNode")) && (KnowledgeBaseTypeValue === "2") ? "block" : "none"
					}}>
						<div className="" style={{ height: "32px", position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>科室：</div>
						<Select mode="multiple" onChange={this.handleLocChange} value={locArr} placeholder="请选择" style={{ width: "100%", marginBottom: "12px" }}>
							{locOption}
						</Select>
					</div>
					<div className="" style={{ height: "32px", position: "relative", paddingLeft: "20px", boxSizing: "border-box", lineHeight: "32px" }}>知识库目录名称：</div>
					<Input placeholder="请输入" value={knowledgeBaseNodeTitle} onChange={this.handleKnowledgeBaseNodeTitleChange} />

				</Modal>
			</div>
		)
	}
}